package top.zhuyougu.entity;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Date;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import top.zhuyougu.utils.DateUtils;

/**
 * <p>
 * 
 * </p>
 *
 * @author 猪油骨
 * @since 2022-12-10 01:15:43
 */
@Getter
@Setter

@TableName("b_admin_log")
@ApiModel(value = "AdminLog对象", description = "")
public class AdminLog implements Serializable {
    private static final long serialVersionUID=1L;
    @ApiModelProperty("主键ID")
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    @ApiModelProperty("操作用户")
    @TableField("username")
    private String username;

    @ApiModelProperty("请求接口")
    @TableField("request_url")
    private String requestUrl;

    @ApiModelProperty("请求方式")
    @TableField("type")
    private String type;

    @ApiModelProperty("操作名称")
    @TableField("operation_name")
    private String operationName;

    @ApiModelProperty("ip")
    @TableField("ip")
    private String ip;

    @ApiModelProperty("ip来源")
    @TableField("source")
    private String source;

    @ApiModelProperty("请求接口耗时")
    @TableField("spend_time")
    private Long spendTime;

    @ApiModelProperty("创建时间")
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    @JsonFormat(pattern = DateUtils.FORMAT_STRING,timezone="GMT+8")
    private Date createTime;

    @ApiModelProperty("请求参数")
    @TableField("params_json")
    private String paramsJson;

    @ApiModelProperty("类地址")
    @TableField("class_path")
    private String classPath;

    @ApiModelProperty("方法名")
    @TableField("method_name")
    private String methodName;

    public AdminLog(){}

    public AdminLog(String ip, String source, String type, String requestUrl, String nickname,
                    String paramsJson, String classPath,
                    String methodName, String operationName,
                    Long spendTime) {
        this.ip = ip;
        this.source = StringUtils.isBlank(source) ? "未知": source;
        this.type = type;
        this.requestUrl = requestUrl;
        this.username = nickname;
        this.paramsJson = paramsJson;
        this.classPath = classPath;
        this.methodName = methodName;
        this.operationName = operationName;
        this.spendTime = spendTime;
    }
}
